package cn.tedu.cwgl.controller;

import cn.tedu.cwgl.entity.Bill;
import cn.tedu.cwgl.entity.Debt;

import cn.tedu.cwgl.entity.UserInfo;
import cn.tedu.cwgl.service.BillService;
import cn.tedu.cwgl.service.DebtService;
import cn.tedu.cwgl.util.PageModel;
import cn.tedu.cwgl.util.Result;
import cn.tedu.cwgl.util.ResultUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class DebtController {
    @Resource
    private DebtService debtService;
    private BillService billService;

    @RequestMapping("/debt/getDebt/{pageNo}/{mPageSize}")
    @ResponseBody
    public Result<Debt> getDebt(Debt debt, @PathVariable int pageNo, @PathVariable int mPageSize) {
        PageModel model = new PageModel<>(pageNo, debt);
        model.setPageSize(mPageSize);
        return debtService.getDebt(model);
    }

    @RequestMapping("/debt/add")
    @ResponseBody
    public Result addDebt(Debt debt, HttpSession httpSession) {

        int result = debtService.addDebt(debt, httpSession);
        if (result > 0) {
            return ResultUtil.success();
        } else {
            return ResultUtil.unSuccess();
        }

    }

    @RequestMapping("/debt/del")
    @ResponseBody
    public Result deleteDebt(Debt debt) {
        int result = debtService.deleteDebt(debt);
        if (result > 0) {
            return ResultUtil.success();
        } else {
            return ResultUtil.unSuccess();
        }
    }

    @RequestMapping("/debt/update")
    @ResponseBody
    public Result updateDebt(Debt debt) {
        int result = debtService.updateDebt(debt);
        if (result > 0) {
            return ResultUtil.success();
        } else {
            return ResultUtil.unSuccess();
        }
    }

    @RequestMapping("/debt/repayment")
    @ResponseBody
    public Result repayment(Debt debt) {
        int result = debtService.deleteDebt(debt);


        if (result > 0) {
            return ResultUtil.success();
        } else {
            return ResultUtil.unSuccess();
        }
    }


}
